package org.glut.controller;

import org.glut.bean.YHAir;
import org.glut.service.YHAirService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
/**
 * 有害气体
 * @author 啊林
 * @date 2022/1/10
 * @time 0:05
 */
public class YHairController {
    @Autowired
    private YHAirService yhAirService;

    @RequestMapping("/yhline")
    public String yhline(){
        return "/myviews/yhline";
    }

    @RequestMapping("/yhpower")
    public String yhpower(){
        return "/myviews/yhpower";
    }

    /**
     * 获取厨房燃气bean
     * @return
     */
    @RequestMapping("/getYH")
    @ResponseBody
    public YHAir getYH(String id) {
        if ("1".equals(id)) {
            return YHAirService.yhAir1;
        }else{
            return YHAirService.yhAir2;
        }
    }

    /**
     * 发命令控制厨房燃气
     * @return
     */
    @RequestMapping("/sendYH")
    @ResponseBody
    public boolean sendYH(String num,String auto,String status,String id) {
        yhAirService.setCmd(num,auto,status,id);
        return true;
    }

    /**
     * 获取厨房燃气上传时间List
     * @return
     */
    @RequestMapping("/getyhTimeDate")
    @ResponseBody
    public List<String> getyhTimeDate(String id){
        List<String> timeList;
        if ("1".equals(id)) {
            timeList = yhAirService.yhtimeList1;
        }else {
            timeList = yhAirService.yhtimeList2;
        }
        if (timeList.size() > 30) {
//            List<String> list = timeList.subList(timeList.size() - 30, timeList.size() - 1);
//            yhAirService.timeList.remove(0);
//            yhAirService.timeList = new ArrayList<>(list);
            timeList.remove(0);
        }
        return timeList;
    }

    /**
     * 获取厨房燃气上传浓度List
     * @return
     */
    @RequestMapping("/getyhNumDate")
    @ResponseBody
    public List<String> getyhNumDate(String id){
        List<String> yhList ;
        if ("1".equals(id)) {
            yhList = yhAirService.yhnumList1;
        }else {
            yhList = yhAirService.yhnumList2;
        }
        if (yhList.size() > 30) {
//                List<String> list = yhList.subList(yhList.size() - 30, yhList.size() - 1);
//                yhAirService.yhList = new ArrayList<>(list);
            int size = yhList.size();
            yhList = yhList.subList(size-30,size);
        }
        return yhList;
    }

    /**
     * 获取厨房燃气上传电量List
     * @return
     */
    @RequestMapping("/getyhpowerDate")
    @ResponseBody
    public List<String> getyhpowerDate(String id){
        List<String> yhList;
        if ("1".equals(id)) {
            yhList = yhAirService.yhpower1;
        }else {
            yhList = yhAirService.yhpower2;
        }
        if (yhList.size() > 30) {
//                List<String> list = yhList.subList(yhList.size() - 30, yhList.size() - 1);
//                yhAirService.yhList = new ArrayList<>(list);
            int size = yhList.size();
            yhList = yhList.subList(size-30,size);
        }
        return yhList;
    }

}
